package fac;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import robocode.BattleResults;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.testing.RobotTestBed;

/**
 * This acceptance test makes sure the ThirdRobotLaw robot can beat the SittingDuck sample robot. It
 * is not acceptable to lose occasionally against SittingDuck.
 * 
 * @author Chris Fang
 */
public class TestTRLVSSittingDuck extends RobotTestBed {

  /**
   * Initiates the battle with SittingDuck and ThirdRobotLaw as the participants.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.SittingDuck,fac.ThirdRobotLaw";
  }

  /**
   * The test will run for 10 rounds.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 10;
  }

  /**
   * The assertion test that determines if ThirdRobotLaw won all matches.
   * 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    // Return the results in order of getRobotNames.
    BattleResults[] battleResults = event.getIndexedResults();
    String robotName = battleResults[1].getTeamLeaderName();
    assertEquals("Check that results[1] is ThirdRobotLaw", robotName, "fac.ThirdRobotLaw*");
    // Check to make sure TRL won at least SIX out of ten rounds.
    assertTrue("Check ThirdRobotLaw winner", battleResults[1].getFirsts() == 10);
  }
}
